<template>
  <div class="app-container">
    <!--搜索栏-->
    <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="68px">
      <el-form-item label="关键字搜索" label-width="85" prop="keyValue">
        <el-input
          v-model="queryParams.keyValue"
          placeholder="请输入搜索关键字"
          clearable
          style="width: 240px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="告警时间" style="width: 308px">
        <el-date-picker
          v-model="dateRange"
          value-format="YYYY-MM-DD"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!--操作栏-->
    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleExport"
          v-hasPermi="['system:role:add']"
          >导出</el-button
        >
      </el-col>
    </el-row> -->
    <!--数据列表-->
    <el-table v-loading="loading" :data="dataList">
      <el-table-column type="index" label="序号" width="55" align="center" />
      <el-table-column label="持卡用户工号" prop="userCode" />
      <el-table-column label="持卡用户" prop="userName" />
      <el-table-column label="定位卡编号" prop="cardMac" :show-overflow-tooltip="true" />
      <el-table-column label="当前电量" prop="electric" />
      <el-table-column label="告警时间" prop="createdAt">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createdAt) }}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.current"
      v-model:limit="queryParams.size"
      @pagination="getList"
    />
  </div>
</template>
<script setup name="LowBattery">
import { listLowBattery, exportLowBattery } from "@/api/screen/lowBattery";
const { proxy } = getCurrentInstance();
const total = ref(0);
const loading = ref(false);
const dataList = ref([]); //数据列表
const dateRange = ref([]);
const data = reactive({
  queryParams: {
    current: 1,
    size: 10,
    keyValue: undefined,
  },
  rules: {},
});
const { queryParams } = toRefs(data);
/** 获取低电量告警数据 */
function getList() {
  loading.value = true;
  if (dateRange.value.length > 0) {
    queryParams.value.beginTime = dateRange.value[0];
    queryParams.value.endTime = dateRange.value[1];
  }
  listLowBattery(queryParams.value).then((response) => {
    loading.value = false;
    dataList.value = response.data.dataList;
    total.value = response.data.totalNum;
  });
}

/** 处理数据导出 */
function handleExport() {}

/** 处理查询 */
function handleQuery() {
  getList();
}
/** 重置 */
function resetQuery() {
  dateRange.value = [];
  queryParams.value = {
    current: 1,
    size: 10,
  };
  proxy.resetForm("queryRef");
  handleQuery();
}
getList();
</script>
